/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package framework.data;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author du
 */
public class ResultQuery
{
    ResultSet rs = null;

    /**
     * ResultQuery
     *
     * @param rs ResultSet
     */
    public ResultQuery( ResultSet rs )
    {
        this.rs = rs;
    }

    /**
     * close
     *
     * @throws SQLException
     */
    public void close() throws SQLException
    {
        if ( rs != null )
        {
            Statement st = rs.getStatement();

            rs.close();

            if ( ! ( st instanceof PreparedStatement ) )
            {
                st.close();
            }

            rs = null;
        }
    }

    /**
     * skip
     *
     * @param count int
     * @throws SQLException
     */
    public void skip( int count ) throws SQLException
    {
        while ( count > 0 )
        {
            if ( ! next() )
            {
                break;
            }

            count--;
        }
    }

    /**
     * next
     *
     * @return boolean
     * @throws SQLException
     */
    public boolean next() throws SQLException
    {
        boolean hasNext = false;

        if ( rs != null )
        {
            hasNext = rs.next();

            if ( ! hasNext )
            {
                rs.getStatement().close();
            }
        }

        return hasNext;
    }
    
    /**
     * getResultSet
     * 
     * @return ResultSet
     */
    public ResultSet getResultSet()
    {
        return rs;
    }
    
    /**
     * setResultSer
     * 
     * @param rs ResultSet
     */
    public void setResultSer( ResultSet rs )
    {
        this.rs = rs;
    }

    /**
     * getString
     *
     * @param column int
     * @return String
     * @throws SQLException
     */
    public String getString( int column ) throws SQLException
    {
        return rs.getString( column );
    }

    /**
     * getBoolean
     *
     * @param column int
     * @return boolean
     * @throws SQLException
     */
    public boolean getBoolean( int column ) throws SQLException
    {
        return rs.getBoolean( column );
    }

    /**
     * getInt
     *
     * @param column int
     * @return int
     * @throws SQLException
     */
    public int getInt( int column ) throws SQLException
    {
        return rs.getInt( column );
    }
}
